package cn.tedu.egweibo0422.base.exception;

import cn.tedu.egweibo0422.base.response.JsonResult;
import cn.tedu.egweibo0422.base.response.Status;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult handleMethodArgumentNotValidException(MethodArgumentNotValidException ex){
        String data = ex.getFieldError().getDefaultMessage();
        log.debug("handleMethodArgumentNotValidException:"+data);
        return new JsonResult(Status.VALIDATED_ERROR,data);
    }

}
